﻿package com.jxl.dnd.combat
{
	public class ArmorClass
	{
		[Bindable]
		public var trueAC:Number;
		public var baseAC:Number = 10;
		public var armorBonus:Number;
		public var shieldBonus:Number;
		public var sizeModifier:Number;
		public var dexterityModifier:Number;
		
		[Bindable]
		public function get armorClass():Number
		{
			return trueAC;
			//return (trueAC + armorBonus + shieldBonus + sizeModifier + dexterityModifier);
		}
		
		public function set armorClass(val:Number):void
		{
			trueAC = val;
		}
		
		public function ArmorClass():void
		{
			trueAC 					= 10;
			armorBonus 				= 0;
			shieldBonus 			= 0;
			sizeModifier 			= 0;
			dexterityModifier 		= 0;
		}
		
		public function toXML():XML
		{
			var acXML:XML = 
				<armorclass>
					<trueac>{trueAC}</trueac>
					<armorbonus>{armorBonus}</armorbonus>
					<shieldbonus>{shieldBonus}</shieldbonus>
					<sizemodifier>{sizeModifier}</sizemodifier>
					<dexteritymodifier>{dexterityModifier}</dexteritymodifier>
				</armorclass>;
			return acXML;
		}
		
		public function buildFromXML(xml:XML):void
		{
			this.trueAC 							= parseInt(xml.armorclass.trueac);
			this.armorBonus 						= parseInt(xml.armorclass.armorbonus);
			this.baseAC 							= parseInt(xml.armorclass.baseac);
			this.dexterityModifier 					= parseInt(xml.armorclass.dexteritymodifier);
			this.shieldBonus 						= parseInt(xml.armorclass.shieldbonus);
			this.sizeModifier						= parseInt(xml.armorclass.sizemodifier);
		}
	}
}